package com.springboot.cloud.demos.producer.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.springboot.cloud.demos.entity.po.VideoLesson;
import com.springboot.cloud.demos.producer.dao.VideoLessonMapper;
import com.springboot.cloud.demos.producer.service.IVideoLessonService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
@Slf4j
@RefreshScope
public class VideoLessonServiceImpl extends ServiceImpl<VideoLessonMapper, VideoLesson> implements IVideoLessonService {

    @Value("${producer.videoLesson:123}")
    private String value;

    @Override
    @CacheEvict(value = "videoLesson",allEntries=true)
    public boolean add(VideoLesson videoLesson) {
        return this.save(videoLesson);
    }

    @Override
    public boolean delete(String id) {
        return this.removeById(id);
    }

    @Override
    public boolean update(VideoLesson videoLesson) {
        return this.updateById(videoLesson);
    }

    @Override
    public VideoLesson get(String id) {
        log.info("value:{}", value);
        return this.getById(id);
    }

    @Override
    public List<Map<String,Object>> query(String levelId) {
        return this.getBaseMapper().queryByLevel(levelId);
    }
}
